package com.whh.zuowen.controller;

import com.whh.common.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class ZuowenController extends BaseController {

    @RequestMapping(value = {"/list", "/"})
    public String list(Model model,
                       @RequestParam(name = "pageNum", defaultValue = "1") int pageNum,
                       @RequestParam(name = "grade", required = false) String grade,
                       @RequestParam(name = "type", required = false) String type){
        model.addAttribute("grade", grade);
        model.addAttribute("type", type);
        model.addAttribute("recordPageInfo", zuowenService.getList(pageNum, grade, type));
        return "/zuowen/zuowen_list.html";
    }

    @RequestMapping("/record/{id}.html")
    public String content(Model model, @PathVariable(name = "id") Integer id) {
        model.addAttribute("record", zuowenService.getRecord(id));
        return "/zuowen/zuowen.html";
    }

}
